home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / MungeImage Source / DInstaller.p < prev    next >
Text File  |  1994-05-11  |  3KB  |  157 lines

  1. {$I-}
  2.  
  3. program DInstaller;
  4.     uses
  5.         EPPC, AppleEvents, RequiredEventSupport, MyDriver;
  6.  
  7.     function GetRegA7: Ptr;
  8.     inline
  9.         $2E8F;
  10.  
  11.     var
  12.         drvr_ref: integer;
  13.  
  14.     var
  15.         have_opened: boolean;
  16.  
  17.     function DoODoc (fss: FSSpec): OSErr;
  18.         var
  19.             err: OSErr;
  20.             pb: ParamBlockRec;
  21.     begin
  22.         have_opened := true;
  23.         with pb do begin
  24.             ioCRefNum := drvr_ref;
  25.             csCode := 666;
  26.             ioMisc := @fss;
  27.         end; (* with *)
  28.         err := PBControlSync(@pb);
  29.         if err <> noErr then begin
  30.             SysBeep(10);
  31.         end; (* if *)
  32.         DoODoc := err;
  33.     end; (* DoODoc *)
  34.  
  35.     procedure CleanUpImageHandles;
  36.         var
  37.             junk: OSErr;
  38.             pb: ParamBlockRec;
  39.     begin
  40.         with pb do begin
  41.             ioCRefNum := drvr_ref;
  42.             csCode := 667;
  43.         end; (* with *)
  44.         junk := PBControlSync(@pb);
  45.     end; (* CleanUpImageHandles *)
  46.  
  47.     function FindFirstVolume (var vref: integer): boolean;
  48.         var
  49.             ndx: integer;
  50.             vpb: HParamBlockRec;
  51.             err: OSErr;
  52.     begin
  53.         FindFirstVolume := false;
  54.         ndx := 1;
  55.         repeat
  56.             vpb.ioCompletion := nil;
  57.             vpb.ioNamePtr := nil;
  58.             vpb.ioVolIndex := ndx;
  59.             err := PBGetVInfo(@vpb, false);
  60.             if (err = noErr) & (vpb.ioVDRefNum = drvr_ref) then begin
  61.                 vref := vpb.ioVRefNum;
  62.                 FindFirstVolume := true;
  63.                 leave;
  64.             end; (* if *)
  65.             ndx := ndx + 1;
  66.         until err <> noErr;
  67.     end; (* FindFirstVolume *)
  68.  
  69.     function UnmountVolumes: boolean;
  70.         var
  71.             err: OSErr;
  72.             vref: integer;
  73.     begin
  74.         err := noErr;
  75.         while (err = noErr) & FindFirstVolume(vref) do begin
  76.             err := UnmountVol(nil, vref);
  77.         end; (* while *)
  78.         CleanUpImageHandles;
  79.         UnmountVolumes := (err = noErr);
  80.     end; (* UnmountVolumes *)
  81.  
  82.     var
  83.         quitNow: boolean;
  84.  
  85.     function DoQuit: OSErr;
  86.     begin
  87.         quitNow := true;
  88.         DoQuit := noErr;
  89.     end; (* DoQuit *)
  90.  
  91.     var
  92.         junkbool: boolean;
  93.         event: EventRecord;
  94.         err: OSErr;
  95.         junk: OSErr;
  96.         junk_vref: integer;
  97.         psn: ProcessSerialNumber;
  98.         proc_info: ProcessInfoRec;
  99.         response: longint;
  100. begin
  101.     if (Gestalt(gestaltSystemVersion, response) <> noErr) | (response < $700) then begin
  102.         ExitToShell;
  103.     end; (* if *)
  104.     InitGraf(@thePort);
  105.     if GetCurrentProcess(psn) <> noErr then begin
  106.         ExitToShell;
  107.     end; (* if *)
  108.     proc_info.processInfoLength := sizeof(proc_info);
  109.     proc_info.processName := nil;
  110.     proc_info.processAppSpec := nil;
  111.     if GetProcessInformation(psn, proc_info) <> noErr then begin
  112.         ExitToShell;
  113.     end; (* if *)
  114.     if (band(proc_info.processMode, modeOnlyBackground) = 0) then begin
  115.         InitFonts;
  116.         InitWindows;
  117.         InitMenus;
  118.         TEInit;
  119.         InitDialogs(nil)
  120.     end; (* if *)
  121.     SetApplLimit(Ptr(longint(GetRegA7) - $2000));
  122.     MaxApplZone;
  123.     MoreMasters;
  124.  
  125.     err := InitAppleEvents(nil, @DoODoc, nil, @DoQuit);
  126.     if err = noErr then begin
  127.         err := InstallRAMDriver('.MungeImage', drvr_ref, true);
  128.         if err = noErr then begin
  129.             quitNow := false;
  130.             while not quitNow do begin
  131.                 junkbool := WaitNextEvent(everyEvent, event, maxlongint, nil);
  132.                 CleanUpImageHandles;
  133.                 case event.what of
  134.                     keyDown: 
  135.                         quitNow := true;
  136.                     kHighLevelEvent: 
  137.                         junk := AEProcessAppleEvent(event);
  138.                     otherwise
  139.                         ;
  140.                 end; (* case *)
  141.                 if have_opened & not (FindFirstVolume(junk_vref)) then begin
  142.                     quitNow := true;
  143.                 end; (* if *)
  144.                 if quitNow then begin
  145.                     if not UnmountVolumes | (CloseDriver(drvr_ref) <> noErr) then begin
  146.                         quitNow := false;
  147.                     end; (* if *)
  148.                 end; (* if *)
  149.             end; (* while *)
  150.             err := RemoveRAMDriver(drvr_ref);
  151.         end
  152.         else begin
  153.             SysBeep(10);
  154.         end; (* if *)
  155.     end; (* if *)
  156. end. (* DInstaller *)
  157.